<?php

namespace app\model\archives_model;

use app\BaseModel;
use app\common\Message;
use think\model\relation\HasMany;

class UserArchiveCustomTemplateModel extends BaseModel
{
    use Message;
    protected $name = 'user_archive_custom_template';

    public function getIsCustomAttr($value,$data)
    {
        return 1;
    }

    /**递归增加记录*/
    public function recurveInsert($newId,$oldPid, $outField, $userId): void
    {
        $arr = UserArchiveTemplateModel::withoutField($outField)->where('pid', '=', $oldPid)->select();
        if (count($arr) > 0) {
            foreach ($arr as $value) {
                $insertArr = $value->toArray();
                $insertArr['user_id'] = $userId;
                $insertArr['pid'] = $newId;
                $insertArr['template_id'] = $value->id;
                unset($insertArr['id']);
                $id = $this->insertGetId($insertArr);
                $this->recurveInsert($id,$value['id'],$outField,$userId);
            }
        }
    }
}